package com.tongji.seller.utils
{
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.utils.setTimeout;
	
	import mx.controls.ToolTip;
	import mx.core.UIComponent;
	import mx.managers.ToolTipManager;

	public class ShowCustomToolTip
	{
		public var toolTip:ToolTip;
		private static const delayTime:int = 3000;
		private var component:UIComponent;
		private var showText:String;
		private var i:int = 0;
		public function ShowCustomToolTip(component:UIComponent,  showText:String)
		{
			this.component = component;
			this.showText = showText;
			showToolTip(component, showText);
		}
		
		public function showToolTip(component:UIComponent, showText:String):void
		{
			switch (component.id)
			{
				case "toSecondBtn":
					componentOverUpHandler();
					setTimeout(componentOutHandler, delayTime);
					break;
				case "searchBtn":
					componentOverDownHandler();
					setTimeout(componentOutHandler, delayTime);
					break;
				case "saveButton":
					componentOverDownHandler();
					setTimeout(componentOutHandler, delayTime);
					break;
			}
			
		}
		
		public function componentOverDownHandler(event:MouseEvent = null):void
		{
			var point:Point = new Point(component.x, component.y);
			point = component.parent.localToGlobal(point);
			toolTip = ToolTipManager.createToolTip(showText, point.x , point.y + component.height, "errorTipBelow") as ToolTip;
		}
				
		public function componentOverUpHandler(event:MouseEvent = null):void
		{
			var point:Point = new Point(component.x, component.y);
			point = component.parent.localToGlobal(point);
			toolTip = ToolTipManager.createToolTip(showText, point.x , point.y - component.height * 2, "errorTipAbove") as ToolTip;
		}
			
		public function componentOutHandler(event:MouseEvent = null):void
		{
			ToolTipManager.destroyToolTip(toolTip);
		}
			
	}
}